<?php

namespace App\Hospital\Controllers;

use App\Hospital\Repositories\FamilyEdu;
use App\Models\FamilyType;
use App\Models\ImportFamily;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class FamilyEduController extends AdminController
{
    protected function description()
    {
        $this->description['index'] = '所有指导文章默认为系统自动推送';

        return $this->description;
    }
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new FamilyEdu(['articleInfo','user','family','team','hospital','familyType']), function (Grid $grid) {
            $grid->model()->where('hospital_id',Admin::user()->hospital_id)->orderby('id','desc');
            $grid->column('articleInfo.title','指导文章');
            $grid->column('family.name','接收人');
            $grid->column('team.name','管理团队');
            $grid->column('familyType.name','推送类型');
            //$grid->column('is_look')->using([0=>'否',1=>'是']);
            $grid->column('created_at','推送时间');
            $grid->disableCreateButton();
            $grid->disableBatchDelete();//禁用批量操作
            $grid->disableRowSelector();//禁用行选择器
            $grid->disableBatchActions();
            $grid->disableActions();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('family.name','接收人');
                $filter->equal('family_type_id','推送类型')->select(FamilyType::query()
                    ->where('type',1)
                    ->pluck('name','id')
                    ->toArray());

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new FamilyEdu(), function (Show $show) {
            $show->field('id');
            $show->field('article_id');
            $show->field('user_id');
            $show->field('family_id');
            $show->field('hospital_id');
            $show->field('team_id');
            $show->field('family_type_id');
            $show->field('is_look');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new FamilyEdu(), function (Form $form) {
            $form->display('id');
            $form->text('article_id');
            $form->text('user_id');
            $form->text('family_id');
            $form->text('hospital_id');
            $form->text('team_id');
            $form->text('family_type_id');
            $form->text('is_look');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
